package com.shanshan.manage.web.controller;

import com.shanshan.manage.common.annotation.Log;
import com.shanshan.manage.common.core.controller.BaseController;
import com.shanshan.manage.common.core.domain.AjaxResult;
import com.shanshan.manage.common.core.page.TableDataInfo;
import com.shanshan.manage.common.enums.BusinessType;
import com.shanshan.manage.common.utils.poi.ExcelUtil;
import com.shanshan.manage.web.domain.ACostName;
import com.shanshan.manage.web.service.IACostNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 费用科目Controller
 *
 * @author zhaoShuHeng
 * @date 2023-08-29
 */
@RestController
@RequestMapping("/aCostName/costName")
public class ACostNameController extends BaseController {
    @Autowired
    private IACostNameService aCostNameService;

    /**
     * 查询费用科目列表
     */
    @PreAuthorize("@ss.hasPermi('aCostName:costName:list')")
    @GetMapping("/list")
    public TableDataInfo list(ACostName aCostName) {
        startPage();
        List<ACostName> list = aCostNameService.selectACostNameList(aCostName);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('aCostName:costName:list')")
    @GetMapping("/listCostName")
    public List<ACostName> listCostName() {
        return aCostNameService.selectACostNameList(new ACostName());
    }

    /**
     * 导出费用科目列表
     */
    @PreAuthorize("@ss.hasPermi('aCostName:costName:export')")
    @Log(title = "费用科目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ACostName aCostName) {
        List<ACostName> list = aCostNameService.selectACostNameList(aCostName);
        ExcelUtil<ACostName> util = new ExcelUtil<ACostName>(ACostName.class);
        util.exportExcel(response, list, "费用科目数据");
    }

    /**
     * 获取费用科目详细信息
     */
    @PreAuthorize("@ss.hasPermi('aCostName:costName:query')")
    @GetMapping(value = "/{costNameId}")
    public AjaxResult getInfo(@PathVariable("costNameId") Long costNameId) {
        return success(aCostNameService.selectACostNameByCostNameId(costNameId));
    }

    /**
     * 新增费用科目
     */
    @PreAuthorize("@ss.hasPermi('aCostName:costName:add')")
    @Log(title = "费用科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ACostName aCostName) {
        return toAjax(aCostNameService.insertACostName(aCostName));
    }

    /**
     * 修改费用科目
     */
    @PreAuthorize("@ss.hasPermi('aCostName:costName:edit')")
    @Log(title = "费用科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ACostName aCostName) {
        return toAjax(aCostNameService.updateACostName(aCostName));
    }

    /**
     * 删除费用科目
     */
    @PreAuthorize("@ss.hasPermi('aCostName:costName:remove')")
    @Log(title = "费用科目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{costNameIds}")
    public AjaxResult remove(@PathVariable Long[] costNameIds) {
        return toAjax(aCostNameService.deleteACostNameByCostNameIds(costNameIds));
    }
}
